<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:f="livcos.org/ns/xslt/function"
  xmlns:extFn="java:org.livcos.ext.xslt.Functions"
  xmlns:extNodeFn="java:org.livcos.ext.xslt.saxon.Functions"
  exclude-result-prefixes="f extFn extNodeFn xs">

	<!-- implementation dependent extension functions (Java, Saxon,...) -->
  
	<xsl:function name="f:isValidUrl" as="xs:boolean" exclude-result-prefixes="#all">
		<xsl:param name="str"/>
		<xsl:value-of select="boolean(extFn:createUri($str))"/>
	</xsl:function>
	
	<xsl:function name="f:uri" xmlns:uri="java:java.net.URI" exclude-result-prefixes="#all">
		<xsl:param name="str"/>
		<xsl:variable name="_tmp">
			<xsl:variable name="uri" select="extFn:createUri($str)"/>
			<xsl:if test="$uri">
				<scheme><xsl:value-of select="uri:getScheme($uri)"/></scheme>
				<user-info><xsl:value-of select="uri:getUserInfo($uri)"/></user-info>
				<host><xsl:value-of select="uri:getHost($uri)"/></host>
				<port><xsl:value-of select="uri:getPort($uri)"/></port>
				<path><xsl:value-of select="uri:getPath($uri)"/></path>
				<query><xsl:value-of select="uri:getQuery($uri)"/></query>
				<fragment><xsl:value-of select="uri:getFragment($uri)"/></fragment>
			</xsl:if>
		</xsl:variable>
		<uri>
			<xsl:for-each select="$_tmp/*[(. != '') and (. != '-1')]">
				<xsl:copy-of select="."/>
			</xsl:for-each>
		</uri>
	</xsl:function>
	
	<xsl:function name="f:relativize-uri" xmlns:uri="java:java.net.URI">
		<xsl:param name="uri"/>
		<xsl:param name="baseUri"/>
		<xsl:value-of select="extFn:relativizeUri($uri, $baseUri)"/>
	</xsl:function>
	
	<xsl:function name="f:request" as="element(response)">
		<xsl:param name="url"/>
		<xsl:param name="spec" as="node()"/>
		<xsl:sequence select="extNodeFn:request($url, $spec)"/>
	</xsl:function>
	
	<xsl:function name="f:request" as="element(response)">
		<xsl:param name="url"/>
		<xsl:sequence select="extNodeFn:request($url)"/>
	</xsl:function>
	
</xsl:stylesheet>
